#include<stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include<errno.h>
#include<string.h>
int main()
{
  pid_t id=fork();
  if(id==0)
  {
    //child
    printf("i am child process\n");
    sleep(5);
    exit(1);
  }
  else{
    //父进程
    int status=0;
    pid_t wait=waitpid(id,&status,0);
    if(wait>0)
    {
      if(WIFEXITED(status))
      //printf("wait success,pid:%d,exit code:%d,exit singal:%d\n",wait,(status>>8)&0xFF,status&0x7F)
      printf("wait success,pid:%d,exit code:%d,exit singal:%d\n",wait,WEXITSTATUS(status),status&0x7F);
      else
        printf("子进程退出异常!");
    }
    else{
      printf("wait failed:%d:%s\n",errno,strerror(errno));
    }
  }
  return 0;
}
